class Solution {
    public:
        int is_pacific[200][200] = {0}; 
        int is_atlantci[200][200] = {0};
        int indexx[4] ={0,0,1,-1};
        int indexy[4] ={-1,1,0,0};
        void dfs(vector<vector<int>>& heights , int i,int j,int board[][200]){
            int n = heights.size(),m=heights[0].size();
            int num = heights[i][j];
            board[i][j] = 1;
            for(int k = 0 ;k< 4 ; k++){
                int row = i+indexx[k];
                int col = j + indexy[k];
                if(row >= 0 && row < n && col >=0 && col < m&& !board[row][col] && heights[row][col] >= num)
                {
                    dfs(heights,row,col,board);
                }
            }
            return;
        }
        vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {
            vector<vector<int>> ret;
            int n = heights.size(),m=heights[0].size();
            for(int i = 0 ; i < n ; i++){
                if(is_pacific[i][0] == 0)   dfs(heights,i,0,is_pacific);
                if(is_atlantci[i][m-1] == 0) dfs(heights,i,m-1,is_atlantci);
            }
            for(int j = 0 ; j < m ; j ++){
                if(is_pacific[0][j] == 0) dfs(heights,0,j,is_pacific);
                if(is_atlantci[n-1][j] == 0) dfs(heights,n-1,j,is_atlantci);
            }
            for(int i = 0 ; i < n;i++){
                for(int j = 0 ;j< m;j++){
                    if(is_atlantci[i][j] == 1 && is_pacific[i][j] ==1)  ret.push_back({i,j});
                }
            }
            return ret;
        }
    };